import 'dart:async';

import 'package:flutter/material.dart';
import 'package:pdf/utils/Toast/MyTosat.dart';
import 'package:pdf/widgets/MyImage.dart';
import 'package:pdf/widgets/MyLocalImage.dart';
import '../../utils/Tool/MyTools.dart';
import '../../widgets/TextView.dart';
import 'package:flutter_swiper_view/flutter_swiper_view.dart';
import 'package:get/get.dart';
import 'package:sp_util/sp_util.dart';

import '../../api/ApiUtils.dart';
import '../../api/request/LoginRegisterRequest.dart';
import '../../base/MyScaffold.dart';
import '../../config/Constant.dart';
import '../../model/GuidePage.dart';
import '../../res.dart';
import '../../sqflite/TablesInit.dart';
import '../../utils/color/ColorUtils.dart';
import '../home/HomeTabBar.dart';
import 'GuidePage.dart';

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int index_ = 0;
  String? first;
  bool OK = false;

  @override
  void initState() {
    super.initState();
    // widget_ = getImg();
    Timer(const Duration(milliseconds: 300), () {
      //语言设置成功
      var lang = SpUtil.getString(Constant.lanuage);
      var code = SpUtil.getString(Constant.code);
      if (lang != null && !MyTools.stringIsEmpty(lang)) {
        var locale = Locale(lang!, code);
        Get.updateLocale(locale).then((value) {
          print("语言设置成功$lang");
        });
      }
      String? firsts = getFirst();
      if (MyTools.stringIsEmpty(firsts)) {
        SpUtil.putInt(Constant.sort, 0);
        print("首次进入");
        SpUtil.putString(Constant.cname, "English");
        Get.off(const GuidePage_());
      } else {
        print("不是首次进入");
        Get.off(const HomeTabBar());
      }
    });

    initDB();
    apiShow(api: info(), success: (value) {});
  }

  @override
  Widget build(BuildContext context) {
    return MyScaffold(
      navBarHide: true,
      body: MyLocalImage(
        Res.startpage,
        onclick: () {
         // Get.off(const HomeTabBar());
        },
      ),
    );
  }


  getFirst() {
    String? temp = SpUtil.getString(Constant.first);
    print("============$temp==========");
    return temp;
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
  }

  void initDB() async {
    TablesInit tables = TablesInit();
    tables.init();
  }
}
